import java.util.ArrayList; 
import java.util.List; 

import EmailSystem.Client; 
import EmailSystem.Util; 
import TestSpecifications.SpecificationManager; 

/**
 * This class implements the actions that can be executed by the test scenarios.
 * (setup() is always executed first to setup the characters and their private keys)
 * @author rhein
 */
public   class  Test_Actions {
	
	public static boolean executedUnimplementedAction = false;

	
	static Client bob, rjh, chuck;

	
	/* Filterfield is possible here. 
	 * It causes some speedup, but no advantage for family, or product based verification.
	 * It might cause more problems than it helps.
	 */ 
	//@FilterField
	public static List<String> actionHistory = new ArrayList<String>();

	
	/**
	 * Bob gets Key of RJH
	 */
	static void bobKeyAdd  () {
		actionHistory.add("bobKeyAdd");
		// unrealistic simplification. Private key == Public key
		bob.addKeyringEntry(rjh, rjh.getPrivateKey());
		Util.prompt("bob added rjhs key");
	}

	

	/**
	 * Bob gets Key of Chuck
	 */
	static void bobKeyAddChuck  () {
		actionHistory.add("bobKeyAddChuck");
		// unrealistic simplification. Private key == Public key
		bob.addKeyringEntry(chuck, chuck.getPrivateKey());
	}

	

	static void bobKeyChange  () {
		actionHistory.add("bobKeyChange");
		Client.generateKeyPair(bob, 777);
	}

	
	static void bobSetAddressBook  () {
		actionHistory.add("bobSetAddressBook");
		bob.addAddressbookEntry("AliasForRJHandChuck", rjh.getName());
		bob.addAddressbookEntry("AliasForRJHandChuck", chuck.getName());
	}

	
	static void bobToAlias  () {
		if (bob.getAddressBookReceiversForAlias("AliasForRJHandChuck").isEmpty()) {
			actionHistory.add("AbortedBobToAlias");
			return;
		}
		actionHistory.add("bobToAlias");
		String subject = "Subject";
		String body = "Body";
		Client.sendEmail(bob, "AliasForRJHandChuck", subject, body);
	}

	

	static void bobToRjh() {
		
		actionHistory.add("bobToRjh");
		String subject = "Subject";
		String body = "Body";
		Client.sendEmail(bob, rjh.getName(), subject, body);
	}

	

	/**
	 * Chuck gets Key of Bob
	 */
	static void chuckKeyAdd  () {
		actionHistory.add("chuckKeyAdd");
		chuck.addKeyringEntry(bob, bob.getPrivateKey());
	}

	

	/**
	 * Delete RJHs private key
	 */
	static void rjhDeletePrivateKey  () {
		actionHistory.add("rjhDeletePrivateKey");
		rjh.setPrivateKey(0);
	}

	
	
	static void rjhEnableForwarding  () {
		actionHistory.add("rjhEnableForwarding");
		rjh.setForwardReceiver(chuck);
	}

	
	
	/**
	 * RJH gets Key of Bob
	 */
	static void rjhKeyAdd  () {
		actionHistory.add("rjhKeyAdd");
		rjh.addKeyringEntry(bob, bob.getPrivateKey());
	}

	

	// actions
	/**
	 * RJH gets Key of Chuck
	 */
	static void rjhKeyAddChuck  () {
		actionHistory.add("rjhKeyAddChuck");
		rjh.addKeyringEntry(chuck, chuck.getPrivateKey());
	}

	

	static void rjhKeyChange  () {
		actionHistory.add("rjhKeyChange");
		Client.generateKeyPair(rjh, 666);
	}

	

	static void rjhSetAutoRespond  () {
		actionHistory.add("rjhSetAutoRespond");
		rjh.setAutoResponse(true);
	}

	

	static void rjhToBob() {
		actionHistory.add("rjhToBob");
		String subject = "subject";
		String body = "body";
		Client.sendEmail(rjh, bob.getName(), subject, body);
	}

	

	static void setup() {
		actionHistory .add("setup");
		SpecificationManager.setupSpecifications();
		Client.resetClients();

		bob = Client.createClient("bob");
		setup_bob(bob);
		Util.prompt("bob: " + bob.getName() + "(ID: " + bob.getId() + ")");
		// rjh = createClient("rjh");
		rjh = Client.createClient("rjh");
		setup_rjh(rjh);
		Util.prompt("rjh: " + rjh.getName() + "(ID: " + rjh.getId() + ")");
		// chuck = createClient("chuck");
		chuck = Client.createClient("chuck");
		setup_chuck(chuck);
		Util
				.prompt("chuck: " + chuck.getName() + "(ID: " + chuck.getId()
						+ ")");
	}

	

	
	static void setup_bob  (Client bob) {
		bob.setPrivateKey(123);
	}

	

	static void setup_chuck  (Client chuck) {
		chuck.setPrivateKey(789);
	}

	

	static void setup_rjh  (Client rjh) {
		rjh.setPrivateKey(456);
	}


}
